package cn.cmcc.online.smsapi.ui.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

import cn.cmcc.online.smsapi.ui.util.DensityUtil;

/**
 * Created by ZhangYifan on 2017/6/19.
 */

public class CustomDotView extends View {
    public static final String DEFAULT_COLOR = "#D8D8D8";
    public static final int DEFAULT_RADIUS = 4;
    private Paint mPaint;
    private int mRadius;
    private String mColor;

    public CustomDotView(Context context) {
        this(context, DEFAULT_COLOR, DEFAULT_RADIUS);
    }

    public CustomDotView(Context context, String color, int radius) {
        super(context);
        mPaint = new Paint();
        setColor(color);
        setRadius(radius);
    }

    public void setColor(String color) {
        if (color == null)
            return;
        this.mColor = color;
    }

    public void setRadius(int dp) {
        if (dp < 0)
            return;
        this.mRadius = DensityUtil.dp2px(getContext(),dp);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor(mColor));
        mPaint.setAntiAlias(true);
        canvas.drawCircle(mRadius, mRadius, mRadius, mPaint);
    }
}
